package cn.kgc.kgde.bookstore.service.impl;


import cn.kgc.kgde.bookstore.dto.EvaluationDTO;
import cn.kgc.kgde.bookstore.entity.Book;
import cn.kgc.kgde.bookstore.entity.Evaluation;
import cn.kgc.kgde.bookstore.mapper.EvaluationMapper;
import cn.kgc.kgde.bookstore.service.EvaluationService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.toolkit.MPJWrappers;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author myt
 * @since 2022-05-23
 */
@Service
public class EvaluationServiceImpl extends MPJBaseServiceImpl<EvaluationMapper, Evaluation> implements EvaluationService {

    @Resource
    private EvaluationMapper evaluationMapper;

    //查询评论表--根据商品id查询
    @Override
    public IPage<EvaluationDTO> evaluationList(Long bookId) {
        IPage<EvaluationDTO> iPage = evaluationMapper.selectJoinPage(new Page<>(1, 10), EvaluationDTO.class, MPJWrappers.lambdaJoin()
                .selectAll(Evaluation.class)
                .selectAll(Book.class)
                .leftJoin(Book.class, Book::getId, Evaluation::getBookId)
                .eq(Evaluation::getBookId, bookId));
        iPage.getRecords().forEach(System.out::println);
        return iPage;
    }
}
